/*
* $Id: Validate.cpp 2 2009-12-23 13:58:02Z volok-aleksej@yandex.ru $
*
* Copyright 2008 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "Validate.h"

CSimbolsValidate::CSimbolsValidate(const std::tstring& strRule)
: m_strRule(strRule){}
std::tstring CSimbolsValidate::GetValidateRule(){
	return m_strRule;
}
bool CSimbolsValidate::bValidate(const std::tstring& strContent, bool bWay){
	if(strContent.size() > m_strRule.size())
		return false;
	for (size_t i = 0; i < strContent.size(); i++){
		if(m_strRule[i] == '*' && _istdigit(strContent[i]))
			continue;
		if(m_strRule[i] == '#' && _istalpha(strContent[i]))
			continue;
		if(m_strRule[i] == strContent[i])
			continue;
		return false;
	}
	return true;
}
void CSimbolsValidate::Free(){
	delete this;
}

CValueValidate::CValueValidate(const std::tstring& strRule)
: m_strRule(strRule){}
std::tstring CValueValidate::GetValidateRule(){
	return m_strRule;
}
bool CValueValidate::bValidate(const std::tstring& strContent, bool bWay){
	double nDbl = _tstof(strContent.c_str());
	size_t nPos = m_strRule.find(' ');
	std::tstring temp, temp1;
	temp.append(m_strRule.begin(), m_strRule.begin() + nPos);
	temp1.append(m_strRule.begin() + nPos + 1, m_strRule.end());
	int m_nUp = int(_tstof(temp1.c_str())*100), m_nDown = int(_tstof(temp.c_str())*100);
	if((int(nDbl*100) <= m_nUp && int(nDbl*100) >= 0 || m_nUp == -100) && (bWay ? TRUE : (m_nDown <= int(nDbl*100))))
		return true;
	return false;
}
void CValueValidate::Free(){
	delete this;
}